#include "usr.h"
#include <stdio.h>
#include <stdlib.h>


int cmp_uid(unsigned  int *uid1,unsigned  int *uid2){
    int res=0;
	for(int i=0;i<10;i++){
		if((res=(*(uid1+i)-*(uid2+i)))!=0){
			return res;
		}
	}
	return res;
}

status usr_init(usr_sqlist *l){
    l->next=NULL;
    return ok;
}

status usr_insert(usr_sqlist *l,usr u){
    usr_sqlist * unode=(usr_sqlist*)malloc(sizeof(usr_sqlist));
    unode->data=u;
    unode->next=NULL;
    usr_sqlist *p;
    p=l;
    while(p && p->next){
        p=p->next;
    }
    p->next=unode;
    return ok;
}
void print_usr(usr u){
    for(int i=0;i<10;i++){
        printf("%d",u.id[i]);
    }
    printf("           ");
    char *name=u.name;
    while((*name)!='\0') printf("%c",*(name++));
    printf("\n");
}
void print_by_uid(usr_sqlist *l,unsigned  int *uid){
	usr_sqlist * p;
	p=l->next;
	while(p){
		if(cmp_uid(p->data.id,uid)==0){
			print_usr(p->data);
			return;
		}
		p=p->next;
	}
}
void usr_traverse(usr_sqlist *l){
    printf("-------------id-------------name-------------\n");
    usr_sqlist *p;
    p=l->next;
    while(p){
        print_usr(p->data);
        p=p->next;
    }
}
